package com.yanggu.scala.chapater08.accompanyObject

import Frock.getNextNum

import scala.beans.BeanProperty

/**
 * 完成scala半生类、伴生对象的课后作业
 */
object TestFrock {

  def main(args: Array[String]): Unit = {

    //获取两次currentNum的值并且进行打印
    var num = Frock.getNextNum
    println(num)
    num = Frock.getNextNum
    println(num)

    //分别创建三个Frock对象, 答应serialNumber的值
    val frock = Frock()
    println(frock.getSerialNumber)
    println(frock)
    println(Frock())
    println(Frock())

  }

}

class Frock {

  @BeanProperty
  val serialNumber = getNextNum

  override def toString = serialNumber.toString

}


object Frock {

  private var currentNum = 1000000L

  def getNextNum = {
    currentNum = currentNum + 100
    currentNum
  }

  def apply(): Frock = new Frock()

}


